home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / AppletFrame.java < prev    next >
Text File  |  1998-09-15  |  3KB  |  106 lines

  1. /*
  2.  * @(#)AppletFrame.java    1.3 96/12/06
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30.  
  31. import java.awt.Frame;
  32. import java.awt.Event;
  33. import java.awt.Dimension;
  34. import java.applet.Applet;
  35. import java.awt.AWTEvent;
  36.  
  37. // Applet to Application Frame window
  38. class AppletFrame extends Frame
  39. {
  40.  
  41.     public static void startApplet(String className, 
  42.                                    String title, 
  43.                                    String args[])
  44.     {
  45.        // local variables
  46.        Applet a;
  47.        Dimension appletSize;
  48.  
  49.        try 
  50.        {
  51.           // create an instance of your applet class
  52.           a = (Applet) Class.forName(className).newInstance();
  53.        }
  54.        catch (ClassNotFoundException e) { return; }
  55.        catch (InstantiationException e) { return; }
  56.        catch (IllegalAccessException e) { return; }
  57.  
  58.        // initialize the applet
  59.        a.init();
  60.        a.start();
  61.   
  62.        // create new application frame window
  63.        AppletFrame f = new AppletFrame(title);
  64.   
  65.        // add applet to frame window
  66.        f.add("Center", a);
  67.   
  68.        // resize frame window to fit applet
  69.        // assumes that the applet sets its own size
  70.        // otherwise, you should set a specific size here.
  71.        appletSize =  a.getSize();
  72.        f.pack();
  73.        f.setSize(appletSize);  
  74.  
  75.        // show the window
  76.        f.show();
  77.   
  78.     }  // end startApplet()
  79.   
  80.   
  81.     // constructor needed to pass window title to class Frame
  82.     public AppletFrame(String name)
  83.     {
  84.        // call java.awt.Frame(String) constructor
  85.        super(name);
  86.     }
  87.  
  88.     // needed to allow window close
  89.     public void processEvent(AWTEvent e)
  90.     {
  91.        // Window Destroy event
  92.        if (e.getID() == Event.WINDOW_DESTROY)
  93.        {
  94.           // exit the program
  95.           System.exit(0);
  96.        }    
  97.    }  // end handleEvent()
  98.  
  99. }   // end class AppletFrame
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.